﻿using System;
using System.Xml.Linq;

namespace System.Web.Mvc
{
    public static class MVCHelpers
    {
        public static string ActionResult(this HtmlHelper helper, string actionResultXml)
        {
            XDocument xDoc = XDocument.Parse(actionResultXml.Replace("<root>", string.Empty).Replace("</root>", string.Empty));
            xDoc.Root.SetAttributeValue("class", "ActionResults");
            xDoc.Root.Name = "ul";
            foreach (var testAction in xDoc.Descendants("TestAction"))
            {
                testAction.Name = "li";
                testAction.SetAttributeValue("class", "ActionResult");
                testAction.Value = string.Format("Action {0}: {1}", testAction.Attribute("Action").Value, testAction.Attribute("Result").Value);
            }

            return xDoc.ToString();
        }
    }
}